package cn.tedu;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class Demo08 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入用户名");
        String username=sc.nextLine();
        System.out.println("请输入密码");
        String password=sc.nextLine();

        try (Connection conn=DBUtils.getConn()){
            Statement s=conn.createStatement();
            String sql="select count(*) from user where username='"+username+"'and password='"+password+"'";
            //执行查询
            ResultSet rs=s.executeQuery(sql);
            rs.next();//游标下移
            //得到结果集对象中的唯一数值
            int count=rs.getInt(1);
            if (count>0){
                System.out.println("登入成功");
            }else {
                System.out.println("登入失败");
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
